package com.jstyle.jclife.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.android.flexbox.FlexboxLayoutManager;
import com.jstyle.jclife.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/6/13.
 */

public class SleepMonthDetailAdapter extends RecyclerViewBaseAdapter<String> {

   List<String>stepData=new ArrayList<>();


    public SleepMonthDetailAdapter(List<String> mDatas) {
        super(mDatas);
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        NormalViewHolder normalViewHolder=(NormalViewHolder)holder;
        normalViewHolder.tvTitleHistoryDate.setText(mDataList.get(position));
        normalViewHolder.tvDataHistoryDay.setTextColor(getTextColor(position,((NormalViewHolder) holder).itemView.getContext()));
        if(position<stepData.size()){
            String data=stepData.get(position);
            if(!TextUtils.isEmpty(data)) normalViewHolder.tvDataHistoryDay.setText(data);
        }
        normalViewHolder.viewHorizontal.setVisibility(getVisibility(position));
        ViewGroup.LayoutParams lp = ((RelativeLayout) (normalViewHolder.tvDataHistoryDay.getParent())).getLayoutParams();
        if (lp instanceof FlexboxLayoutManager.LayoutParams) {
            FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) lp;
            flexboxLp.setFlexBasisPercent(0.333f);
        }

    }
    private int getTextColor(int position, Context context){
        int color=0;
        switch (position){

            case 0:
                color=context.getResources().getColor(R.color.week_sleep_awake);
                break;
            case 1:
                color=context.getResources().getColor(R.color.week_sleep_deep);
                break;
            case 2:
                color=context.getResources().getColor(R.color.week_sleep_light);
                break;
            case 3:
                color=context.getResources().getColor(R.color.week_sleep_light);
                break;
        }
        return  color;
    }
    public class NormalViewHolder extends BaseViewHolder {
        @BindView(R.id.tv_data_history_day)
        TextView tvDataHistoryDay;
        @BindView(R.id.view_Horizontal)
        View viewHorizontal;
        @BindView(R.id.view_Vertical)
        View viewVertical;
        @BindView(R.id.tv_title_history_date)
        TextView tvTitleHistoryDate;

        public NormalViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(getLayoutId(viewType), parent, false);
       BaseViewHolder baseViewHolder = new NormalViewHolder(view);
        return baseViewHolder;
    }


    private int getVisibility(int position) {
        int visibility = 0;
        visibility = position == 2 ? View.INVISIBLE : View.VISIBLE;
        return visibility;
    }


    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.item_history_show;
    }

    public void setData(List<String> data) {
        this.mDataList = data;
        notifyDataSetChanged();
    }
    public void setStepData(List<String>datas) {
        this.stepData = datas;
        notifyDataSetChanged();
    }

}
